package space.edge.d.demo.qrcode.codescanner.scanner;

import android.os.Handler;
import android.os.Looper;

import java.util.concurrent.CountDownLatch;

/**
 * Created by gsl on 2017/10/30.
 * 解码一帧图像的线程
 */

public class DecodeThread extends Thread {

    private Handler decodeHandler;
    private PreviewHandler previewHandler;
    private CountDownLatch latch;


    DecodeThread(PreviewHandler previewHandler) {
        this.previewHandler = previewHandler;
        latch = new CountDownLatch(1);
    }

    public Handler getHandler() {
        try{
            latch.await();
        }catch (InterruptedException e){
            e.printStackTrace();
        }
        return decodeHandler;
    }

    @Override
    public void run() {
        Looper.prepare();
        decodeHandler = new DecodeHandler(previewHandler);
        latch.countDown();
        Looper.loop();
    }
}
